<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24">
        <div class="h_top">
          <div class="bread_title">
            <span>更新申请</span>
          </div>
          <div class="save_button">
            <div class="buttonBox">
              <el-button type="primary" icon="el-icon-back" size="mini" @click="goBack">返回</el-button>
            </div>
            <div class="buttonBox">
              <el-button type="primary" icon="el-icon-document-checked" size="mini" @click="save">保存</el-button>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <div>
      <el-row>
        <el-col :span="24">
          <el-form ref="form" :model="data" :inline="true" :rules="formRules">
            <el-input v-model="data.id" type="hidden" />
            <el-row :gutter="10">
              <el-col :span="3">
                <el-form-item prop="coding">
                  <div>编号</div>
                  <el-input v-model="data.coding" size="mini" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="name">
                  <div>申请名称</div>
                  <el-input v-model="data.name" size="mini" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="3">
                <el-form-item prop="workshop">
                  <div>所属车间</div>
                  <v-select v-model="data.workshop" action="workshopList" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="3">
                <el-form-item prop="line">
                  <div>所属生产线</div>
                  <v-select v-model="data.line" action="lineList" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="process">
                  <div>所属工位</div>
                  <v-select v-model="data.process" action="processList" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="3">
                <el-form-item prop="category">
                  <div>资产类别</div>
                  <el-select v-model="data.category" placeholder="请选择" size="mini" disabled>
                    <el-option v-for="(item, index) in applyCategory" :key="index" :label="item" :value="index" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="equipment_id">
                  <div>资产</div>
                  <v-select v-model="data.equipment_id" action="eqList" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="3">
                <el-form-item prop="status">
                  <div>状态</div>
                  <el-select v-model="data.status" placeholder="请选择" size="mini" disabled>
                    <el-option v-for="(item, index) in applyOrderStatus" :key="index" :label="item" :value="index" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="lose_date">
                  <div>提报时间</div>
                  <el-date-picker v-model="data.lose_date" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" size="mini" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="2">
                <el-form-item prop="type">
                  <div>类别</div>
                  <el-select v-model="data.category" placeholder="请选择" size="mini" disabled>
                    <el-option v-for="(item, index) in applyType" :key="index" :label="item" :value="index" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="priority">
                  <div>优先程度</div>
                  <el-select v-model="data.priority" placeholder="请选择" size="mini" disabled>
                    <el-option v-for="(item, index) in priority" :key="index" :label="item" :value="index" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="3">
                <el-form-item prop="influence">
                  <div>失效对工作的影响</div>
                  <el-select v-model="data.influence" placeholder="请选择" size="mini" disabled>
                    <el-option v-for="(item, index) in influence" :key="index" :label="item" :value="index" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="3">
                <el-form-item prop="mode">
                  <div>故障模式</div>
                  <el-select v-model="data.mode" placeholder="请选择" size="mini" disabled>
                    <el-option v-for="(item, index) in applyMode" :key="index" :label="item" :value="index" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="5">
                <el-form-item prop="error">
                  <div>错误信息</div>
                  <el-input v-model="data.error" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="sort">
                  <div>排序</div>
                  <el-input v-model="data.sort" size="mini" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <el-tabs>
            <el-tab-pane label="描述">
              <el-row :gutter="10">
                <el-col :span="6">
                  <div>
                    <span>创建时间日期</span>
                    <el-input v-model="data.create_time" placeholder="创建时间日期" class="mtb10" :disabled="true" size="mini" />
                  </div>
                  <div>
                    <span>创建人</span>
                    <el-input v-model="data.cr_admin.name" placeholder="创建人" class="mtb10" :disabled="true" size="mini" />
                  </div>
                  <div v-if="data.update_time">
                    <div>
                      <span>最近更新</span>
                      <el-input v-model="data.update_time" placeholder="最近更新" class="mtb10" :disabled="true" size="mini" />
                    </div>
                    <div>
                      <span>更新者</span>
                      <el-input v-model="data.upadmin" placeholder="更新者" class="mtb10" :disabled="true" size="mini" />
                    </div>
                  </div>
                  <div v-if="data.status">
                    <div>
                      <span>工单</span>
                      <el-input v-model="data.wordorder_id" placeholder="工单" class="mtb10" :disabled="true" size="mini" />
                    </div>
                  </div>
                </el-col>
                <el-col :span="18">
                  <div class="mb10">描述</div>
                  <Tinymce id="content" v-model="data.content" />
                </el-col>
              </el-row>
            </el-tab-pane>
          </el-tabs>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import API from '@/api/maintain/apply'
import { applyOrderStatus, applyType, applyCategory, priority, influence, applyMode } from '@/utils/options'
import Tinymce from '@/components/Tinymce/index'
import VSelect from '@/components/select'
export default {
  components: {
    Tinymce,
    VSelect
  },
  inject: ['backUrl', 'delOne', 'update', 'goUrl'],
  data() {
    return {
      data: {
        'cr_admin': {
          'name': ''
        }
      },
      applyOrderStatus,
      applyType,
      applyCategory,
      priority,
      influence,
      applyMode,
      formRules: {
        sort: [
          {
            required: true,
            message: '请输入排序',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  created() {
    const id = this.$route.params.id
    API.apply(id).then(response => {
      if (response.error_code === 65404) {
        this.$alert('您请求的申请单不存在', '错误', {
          confirmButtonText: '确定',
          callback: () => {
            this.backUrl()
          }
        })
      }
      this.data = response.data
    })
  },
  methods: {
    confirmDel() {
      const id = this.data.id
      this.delOne(API, id, true)
    },
    save() {
      const thisData = this.data
      const thisForm = this.$refs.form
      this.update(API, thisData, thisForm)
    },
    goBack() {
      this.goUrl('/project/apply')
    }
  }
}
</script>
